# api_gateway.py
from flask import Flask, jsonify
import requests


from jaeger_client import Config


def init_tracer(service):
    config = Config(
        config={
            'sampler': {'type': 'const', 'param': 1},
            'local_agent': {
                'reporting_host': 'jaeger',
                'reporting_port': '6831',
            },
            'logging': True,
        },
        service_name=service,
        validate=True,
    )
    return config.initialize_tracer()




app = Flask(__name__)
tracer = init_tracer('api-gateway')


@app.route('/users')
def get_users():
    response = requests.get('http://user-service:5001/users')
    return jsonify(response.json())

@app.route('/orders')
def get_orders():
    response = requests.get('http://order-service:5002/orders')
    return jsonify(response.json())

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
